package org.bing.engine.health.task;

import org.bing.engine.common.logging.Log;
import org.bing.engine.common.logging.LogFactory;
import org.bing.engine.controller.preference.PreferenceManager;
import org.bing.engine.controller.service.MessageSender;
import org.bing.engine.jmx.ManagementFactory;

public abstract class AbstractHealthTask implements Runnable {
    protected static final Log logger = LogFactory.getLog(AbstractHealthTask.class);
    protected PreferenceManager preference;
    protected MessageSender sender;
    protected ManagementFactory managementFactory;

    public void setManagementFactory(ManagementFactory factory) {
        this.managementFactory = factory;
    }

    public void setMessageSender(MessageSender sender) {
        this.sender = sender;
    }

    public void setPreferenceManager(PreferenceManager fm) {
        this.preference = fm;
    }

    public final void run() {
        try {
            if (logger.isDebugEnabled()) {
                logger.debug(" - start task " + this.getClass().getSimpleName());
            }
            doTask();
        } catch (Throwable e) {
            logger.error("Fail to run task ", e);
        }
    }

    public abstract void doTask();
}
